<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script type="text/javascript" src="webcam.js"></script>      
            <script type="text/javascript" src="ajax.js"></script>
            <link rel="stylesheet" type="text/css" href="style.css"/>
            <title>:: Portaria - Visitantes ::</title>
            <script language="JavaScript">
                webcam.set_api_url( 'test.php' );
                webcam.set_quality( 90 ); // JPEG quality (1 - 100)
                webcam.set_shutter_sound( false ); // play shutter click sound
                

            </script>
        </meta>
    </head>
    <body>
        <div name="cam" >
            <script language="JavaScript">
                document.write( webcam.get_html(320, 240) );
                webcam.set_hook( 'onComplete', 'my_completion_handler' );               
                function take_snapshot() 
                {
                    webcam.snap();
                }
		
                function my_completion_handler(msg) {
                    
                    
                           
                    if (msg.match(/(http\:\/\/\S+)/)) {
                        
                        var image_url = RegExp.$1;
                        webcam.reset();
                        opener.document.getElementById('div_foto').innerHTML = '<img src="' + image_url + '" />'
                        window.close();             
                        
                    }
                    else alert("PHP Error: " + msg);
                   
                }
            </script>
        </div>
        <input type="button" value="Tirar foto." id="tirar_foto" onClick="take_snapshot()" />
    </body>
</html>